export function getLocalStorage(key) {
	let value = localStorage.getItem(key)
	let jsonObj = JSON.parse(value) 
	return  jsonObj 
}

export function setLocalStorage(key,value) {
	value = JSON.stringify(value)
	localStorage.setItem(key,value)
}

export function removeLocalStorage(key) {
	localStorage.removeItem(key)
}

export function clearLocalStorage() {
	localStorage.clear()
}

/**
 * 设置图书离线缓存的属性值
 * @param {Object} fileName 书名目录
 * @param {Object} key  属性值 key
 * @param {Object} value  属性值 value
 */
export function setBookObjectProperty(fileName,key,value) {
	let book = getLocalStorage(`${fileName}-info`)
	if(!book) {
		book = {}
	}
	book[key] = value
	setLocalStorage(`${fileName}-info`,book)
}

/**
 * 获取图书离线缓存的属性值
 * @param {Object} fileName 书名目录
 * @param {Object} key  属性值 key
 */
export function getBookObjectProperty(fileName,key) {
	let book =  getLocalStorage(`${fileName}-info`)
	if(!book) {
		return null
	}
	return book[key]
}


